package com.grandbroad.eim.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.vod.bean.AlbumBean;
import com.grandbroad.eim.R;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 专辑列表适配器
 */
public class AlbumListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<AlbumBean> albumBeanList = new ArrayList<>();

    public void setAlbumBeanList(List<AlbumBean> albumBeanList) {
        this.albumBeanList = albumBeanList;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.album_item, viewGroup, false);
        return new AlbumViewHolder(view);
    }
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (viewHolder instanceof AlbumViewHolder) {
            AlbumViewHolder albumViewHolder = (AlbumViewHolder) viewHolder;
            AlbumBean albumBean = albumBeanList.get(i);
            x.image().bind(albumViewHolder.imgAlbumImg, albumBean.getCover());
            albumViewHolder.tvAlbumName.setText(albumBean.getName());
            albumViewHolder.tvAlbumDes.setText(albumBean.getDescription());
            //默认为付费，等待后台接口修改
            //有了
            if (albumBean.getPay() == 1)
            {
                albumViewHolder.tvAlbumTag.setText("付费");
                albumViewHolder.tvAlbumTag.setBackgroundResource(R.drawable.live_tag_bg);
            }
            else
            {
                albumViewHolder.tvAlbumTag.setText("免费");
                albumViewHolder.tvAlbumTag.setBackgroundResource(R.drawable.rec_tag_bg);
            }

        }
    }

    @Override
    public int getItemCount() {
        return albumBeanList.size();
    }

    /***
     * viewholder
     */
    class AlbumViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_album_tag)
        TextView tvAlbumTag;
        @BindView(R.id.img_album_img)
        ImageView imgAlbumImg;
        @BindView(R.id.tv_album_name)
        TextView tvAlbumName;
        @BindView(R.id.tv_album_des)
        TextView tvAlbumDes;
        public AlbumViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
